package leetcode.treeCode.week3.leetcode_437;

class Solution {
    private int count = 0;
    public int pathSum(TreeNode root, int targetSum) {
        if (root == null ) return 0;
        dfs(root , targetSum);
        pathSum(root.left, targetSum);
        pathSum(root.right, targetSum);
        return count;
    }
    public void dfs(TreeNode node , int targetSum){
        if (node == null ) return;
        if (node.val == targetSum){
            count++;
        }
        dfs (node.left , targetSum - node.val);
        dfs (node.right , targetSum - node.val);
    }

}